package com.briup.day17;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

public class Test_test {
    public void test1(Collection<Integer> c){
        System.out.println(c);
    }
    public void test2(Collection<Integer> c){
        System.out.println(c);
    }
    public void test(Collection<?> c){
        System.out.println("泛型参数"+c);
    }

    public static void main(String[] args) {
        List<? extends Number> list ;
        list = new ArrayList<Integer>();
        list = new ArrayList<Number>();
        list = new ArrayList<Double>();
        List<? super Number> list1;//只能接收number及其(number)父类形和实现的接口
        ArrayList<Integer> list3 = new ArrayList<Integer>();
        ArrayList<Long> list4 = new ArrayList<Long>();
// 大家大致能看懂即可，后续反射章节会补充
        System.out.println(list3.getClass() == list4.getClass());
    }
    public static void main02(String[] args) {
//        Collection<?> c=new ArrayList<>();
//        c.add(null);//因为所有引用类型共同值是null
        ArrayList<String> list=new ArrayList<>();
        list.add("hello1");
        list.add("hello2");
        list.add("hello3");
        Collection<?> c=list;
        //通配符不可以往集合中添加元素
        for (Object o:c){
            System.out.println(o);
        }

    }
    public static void main01(String[] args) {
        Test_test t = new Test_test();
//        Collection<Integer> c1 = new ArrayList<>();
//        c1.add(1);
//        c1.add(2);
//        c1.add(3);
//        t.test1(c1);
//        t.test1(new ArrayList<String>());
//        t.test2(new ArrayList<String>());
        t.test(new ArrayList<Integer>());
        t.test(new ArrayList<String>());
        t.test(new ArrayList<Double>());
    }
}
